//引入封装好的axios实例
import instance from "./instance";

// 通用的POST请求 
export function Post(url, data, config) {
  const promise = instance
    .post(url, data, config)
    .catch((err) => console.log("err=", err));
  return promise;
}

// 通用的GET请求 
export function Get(url, data, config, defaultInstance = instance) {
  if (data) {
    const p = new URLSearchParams();
    for (let key in data) {
      p.append(key, data[key]);
    }
    url += `?${p.toString()}`;//拼接路径
  }

  return defaultInstance
    .get(url, config)
    .catch((err) => console.log("err=", err));
}
